package com.zyh.javaseshuzujinjiekaoshi;

import java.util.Arrays;

public class Test4 {
    public static void main(String[] args) {
        int[] old = {1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 5, 7, 0, 5};
        System.out.println(Arrays.toString(old));
        m1(old);
    }

    private static void m1(int[] old) {
        int count = 0;
        for (int i = 0; i < old.length; i++) {
            if (old[i] == 0) {
                count++;
            }
        }
        System.out.println("count = " + count);
        int[] newArr = new int[old.length - count];
        int index = 0;
        for (int i = 0; i < old.length; i++) {
            if (old[i] != 0) {
                newArr[index++] = old[i];
            }
            if (index == newArr.length) {
                break;
            }
        }
        System.out.println(Arrays.toString(newArr));
        Arrays.sort(newArr);
        System.out.println(Arrays.toString(newArr));

    }
}
